<!DOCTYPE html>
<html>
<head>
    <title>系统厂家</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div v-show="showList">
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="search-group">
                <i-col span="4">
                    <i-input v-model="q.name" @on-enter="query" placeholder="名称"/>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.code" @on-enter="query" placeholder="编码"/>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>

    <Card v-show="!showList">
        <p slot="title">{{title}}</p>
        <i-form ref="formValidate" :model="factoryType" :rules="ruleValidate" :label-width="80">
            <Row>
                <i-col span="11">
                    <Form-item label="名称" prop="faName">
                        <i-input v-model="factoryType.faName" placeholder="名称"/>
                    </Form-item>
                </i-col>
                <i-col span="11">
                    <Form-item label="编码" prop="faCode">
                        <i-input v-model="factoryType.faCode" placeholder="编码"/>
                    </Form-item>
                </i-col>
            </Row>
            <Row>
                <i-col span="11">
                    <Form-item label="备注" prop="remark">
                        <i-input type="textarea" v-model="factoryType.remark" placeholder="备注"/>
                    </Form-item>
                </i-col>
            </Row>
            <Form-item>
                <i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
                <i-button type="warning" @click="reload" style="margin-left: 8px"/>
                返回</i-button>
                <i-button type="info" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
            </Form-item>
        </i-form>
    </Card>
</div>
<script>
    var type = getQueryString("type");
    $(function () {
        $("#jqGrid").Grid({
            url: '../factorytype/list?type='+type,
            rownumWidth: 40,
            colModel: [
                {label: '编码', name: 'faCode', index: 'FA_CODE', width: 120},
                {label: '名称', name: 'faName', index: 'FA_NAME', width: 120},
                {
                    label: '供应商类型', name: 'type', index: 'TYPE', width: 120,
                    formatter: function (value, col, row) {
                        return sysEnums.FACTORY_TYPE[value];
                    }
                },
                {label: '厂家代号', name: 'selfCode', index: 'SELF_CODE', width: 120},
                {label: '备注', name: 'remark', index: 'REMARK', width: 150},
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
            ]
        });
    });
    let vm = new Vue({
        el: '#rrapp',
        data: {
            showList: true,
            title: null,
            factoryType: {isDel: 1, remark: '', faName: '', faCode: '', id: '',},
            ruleValidate: {
                name: [
                    {required: true, message: '名称不能为空', trigger: 'blur'}
                ]
            },
            q: {
                name: '',
                code:''
            }
        },
        methods: {
            query: function () {
                vm.reload();
            },
            reload: function (event) {
                vm.showList = true;
                let page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    postData: {'name': vm.q.name,'code':vm.q.code},
                    page: page
                }).trigger("reloadGrid");
                vm.handleReset('formValidate');
            },
            reloadSearch: function () {
                vm.q = {
                    name: '',
                    code:''
                };
                vm.reload();
            },
        }
    });
    var getFacType = function () {
        let result = getSelectedRowData("#jqGrid");
        var id = result.id;
        if (id == null) {
            return false;
        } else {
            return result;
        }
    }
</script>

</body>
</html>
